namespace Lays.Manage.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class UpdateNewsEntity : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.Comments", "News_Id", "dbo.News");
            DropForeignKey("dbo.NewsTypes", "News_Id", "dbo.News");
            DropIndex("dbo.Comments", new[] { "News_Id" });
            DropIndex("dbo.NewsTypes", new[] { "News_Id" });
            CreateTable(
                "dbo.CommentsNews",
                c => new
                    {
                        Comments_Id = c.Int(nullable: false),
                        News_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Comments_Id, t.News_Id })
                .ForeignKey("dbo.Comments", t => t.Comments_Id, cascadeDelete: true)
                .ForeignKey("dbo.News", t => t.News_Id, cascadeDelete: true)
                .Index(t => t.Comments_Id)
                .Index(t => t.News_Id);
            
            CreateTable(
                "dbo.NewsTypeNews",
                c => new
                    {
                        NewsType_Id = c.Int(nullable: false),
                        News_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.NewsType_Id, t.News_Id })
                .ForeignKey("dbo.NewsTypes", t => t.NewsType_Id, cascadeDelete: true)
                .ForeignKey("dbo.News", t => t.News_Id, cascadeDelete: true)
                .Index(t => t.NewsType_Id)
                .Index(t => t.News_Id);
            
            DropColumn("dbo.Comments", "News_Id");
            DropColumn("dbo.NewsTypes", "News_Id");
        }
        
        public override void Down()
        {
            AddColumn("dbo.NewsTypes", "News_Id", c => c.Int());
            AddColumn("dbo.Comments", "News_Id", c => c.Int());
            DropForeignKey("dbo.NewsTypeNews", "News_Id", "dbo.News");
            DropForeignKey("dbo.NewsTypeNews", "NewsType_Id", "dbo.NewsTypes");
            DropForeignKey("dbo.CommentsNews", "News_Id", "dbo.News");
            DropForeignKey("dbo.CommentsNews", "Comments_Id", "dbo.Comments");
            DropIndex("dbo.NewsTypeNews", new[] { "News_Id" });
            DropIndex("dbo.NewsTypeNews", new[] { "NewsType_Id" });
            DropIndex("dbo.CommentsNews", new[] { "News_Id" });
            DropIndex("dbo.CommentsNews", new[] { "Comments_Id" });
            DropTable("dbo.NewsTypeNews");
            DropTable("dbo.CommentsNews");
            CreateIndex("dbo.NewsTypes", "News_Id");
            CreateIndex("dbo.Comments", "News_Id");
            AddForeignKey("dbo.NewsTypes", "News_Id", "dbo.News", "Id");
            AddForeignKey("dbo.Comments", "News_Id", "dbo.News", "Id");
        }
    }
}
